package com.enjoybyte.pangucloud.common.generator;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import lombok.extern.slf4j.Slf4j;

import java.nio.file.Paths;

@Slf4j
public class CodeGenerator {
    public static void main(String[] args) {
        FastAutoGenerator.create("jdbc:mysql://localhost:3306/pangu-cloud?serverTimezone=Asia/Shanghai", "root", "root")
                .globalConfig(builder -> {
                    builder.author("lijunjie") // 设置作者
                            .enableSpringdoc()
                            .dateType(DateType.ONLY_DATE)
                            .outputDir(Paths.get(System.getProperty("user.dir")) + "/pangu-consumer" +"/src/main/java"); // 指定输出目录
                })
                .packageConfig(builder ->
                        builder.parent("com.enjoybyte.pangucloud.consumer") // 设置父包名
                                .entity("domain")
                                .mapper("mapper")
                                .service("service")
                                .serviceImpl("service.impl")
                                .xml("mapper.xml")
                )
                .strategyConfig(builder ->
                        builder.addInclude("order_info") // 设置需要生成的表名
                                .entityBuilder()
                                .enableLombok()
                                .enableTableFieldAnnotation()
                                .idType(IdType.ASSIGN_ID)
                                .naming(NamingStrategy.underline_to_camel)
                                .columnNaming(NamingStrategy.underline_to_camel)
                                .enableActiveRecord()

                                .controllerBuilder()
                                .enableRestStyle()

                                .mapperBuilder()
                                .enableBaseColumnList() // 启用 columnList (通用查询结果列)
                                .enableBaseResultMap() // 启动resultMap
                )
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
}
